package com.vil.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vil.common.ServerResponse;
import com.vil.entity.Repair;
import com.vil.mapper.RepairMapper;
import com.vil.service.RepairService;

@Service
public class RepairServiceImpl implements RepairService {
	@Autowired
	 private RepairMapper mapper;
	
	@Override
	public ServerResponse deleteByPrimaryKey(Long id) {
		int i =mapper.deleteByPrimaryKey(id);
		if(i>0){
			return ServerResponse.buildSuccessMsg("删除成功");
		}
		return ServerResponse.buildErrorMsg("删除失败");
	}
	

	@Override
	public ServerResponse insertSelective(Repair record) {
		record.setCreate_time(new Date());
		int i =mapper.insertSelective(record);
		if(i>0){
			return ServerResponse.buildSuccessMsg("新增成功");
		}
		return ServerResponse.buildErrorMsg("新增失败");
	}

	@Override
	public ServerResponse updateByPrimaryKeySelective(Repair record) {
		int i=mapper.updateByPrimaryKeySelective(record);
		if (i>0){
            return ServerResponse.buildSuccessMsg("修改成功");
        }
        return ServerResponse.buildErrorMsg("修改失败");
	}

	@Override
	public ServerResponse getListByManyConditions(Integer pageIndex, Integer pageSize, Repair record) {
		PageHelper.startPage(pageIndex,pageSize);
		List<Repair> list=mapper.getListByManyConditions(record);
		PageInfo pageInfo = new PageInfo(list);
		return ServerResponse.buildSuccessData(pageInfo);
	}

	@Override
	public ServerResponse getById(Long id) {
		Repair repair =mapper.selectByPrimaryKey(id);
		if (repair==null){
            return ServerResponse.buildErrorMsg("不存在该保修信息");
        }
        return ServerResponse.buildSuccessData(repair);
	}

	@Override
	public ServerResponse deleteMany(Long[] ids) {
		int i = mapper.deleteMany(ids);
        if (i>0){
            return ServerResponse.buildSuccessMsg("批量删除成功");
        }
        return ServerResponse.buildErrorMsg("批量删除失败");
	}

//	@Override
//	public ServerResponse getListByManyConditions(Integer pageIndex, Integer pageSize, String village) {
//		PageHelper.startPage(pageIndex,pageSize);
//		List<Repair> list=mapper.getListByManyConditions(village);
//		PageInfo activePageInfo = new PageInfo(list);
//		return ServerResponse.buildSuccessData(activePageInfo);
//	}

}
